package cz.muni.fi.PA165.services;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


import cz.muni.fi.PA165.dao.AuthorDAO;
import cz.muni.fi.PA165.dto.AuthorDTO;
import cz.muni.fi.PA165.entities.Author;
import cz.muni.fi.PA165.transfers.AuthorT;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.EJB;
import javax.ejb.Stateless;

/**
 *
 * @author Dominik, Vlasta Ramik
 */
@Stateless
public class AuthorServiceImpl implements AuthorService {

    @EJB 
    private AuthorDAO authorDAO;
    
    @Override
    public void createAuthor(AuthorDTO author) {
        authorDAO.createAuthor(AuthorT.DTOtoAuthor(author));
    }

    @Override
    public AuthorDTO getAuthor(Long id) {
        return AuthorT.AuthorToDTO(authorDAO.getAuthor(id));
    }

    @Override
    public List<AuthorDTO> getAllAuthors() {
        List<AuthorDTO> allAuthorsDTO = new ArrayList();
        List<Author> allAuthors = authorDAO.getAllAuthors();
        for(Author author : allAuthors) {
            allAuthorsDTO.add(AuthorT.AuthorToDTO(author));
        }
        return allAuthorsDTO;
    }

    @Override
    public void updateAuthor(AuthorDTO author) {
        authorDAO.updateAuthor(AuthorT.DTOtoAuthor(author));
    }

    @Override
    public void deleteAuthor(AuthorDTO author) {
        authorDAO.deleteAuthor(AuthorT.DTOtoAuthor(author));
    }
    
}
